//
//  RyueNaviController.swift
//  RyueWeibo
//
//  Created by jugg on 2016/11/30.
//  Copyright © 2016年 Renyue'husband. All rights reserved.
//

import UIKit

class RyueNaviController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate=self

}

   @objc private func popViewControllerClick() -> () {
        self.popViewController(animated: true)
        
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if viewControllers.count>0 {
            viewController.hidesBottomBarWhenPushed=true
        }
        
        super.pushViewController(viewController, animated: animated)
        
        if viewControllers.count>1 {
            if viewControllers.count==2 {
                let title = viewControllers.first!.title
                
                viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(title: title!, imageName: "navigationbar_back_withtext", target: self, action: #selector(popViewControllerClick))
            
            }else{
                viewController.navigationItem.leftBarButtonItem=UIBarButtonItem(title: "返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(popViewControllerClick))
            }
            viewController.title="当前是第\(viewControllers.count)个控制器"
            
        }
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

extension RyueNaviController:UIGestureRecognizerDelegate
{
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if viewControllers.count==1 {
            return false
        }else{
            return true
        }
    }
}




